package com.ruoyi.finance.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.finance.domain.Distributorincome;
import com.ruoyi.finance.service.IDistributorincomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 分销员收入Controller
 * 
 * @author ruoyi
 * @date 2025-06-10
 */
@RestController
@RequestMapping("/distributorIncome/distributorincome")
public class DistributorincomeController extends BaseController
{
    @Autowired
    private IDistributorincomeService distributorincomeService;

    /**
     * 查询分销员收入列表
     */
    @PreAuthorize("@ss.hasPermi('distributorIncome:distributorincome:list')")
    @GetMapping("/list")
    public TableDataInfo list(Distributorincome distributorincome)
    {
        startPage();
        List<Distributorincome> list = distributorincomeService.selectDistributorincomeList(distributorincome);
        return getDataTable(list);
    }

    /**
     * 导出分销员收入列表
     */
    @PreAuthorize("@ss.hasPermi('distributorIncome:distributorincome:export')")
    @Log(title = "分销员收入", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Distributorincome distributorincome)
    {
        List<Distributorincome> list = distributorincomeService.selectDistributorincomeList(distributorincome);
        ExcelUtil<Distributorincome> util = new ExcelUtil<Distributorincome>(Distributorincome.class);
        util.exportExcel(response, list, "分销员收入数据");
    }

    /**
     * 获取分销员收入详细信息
     */
    @PreAuthorize("@ss.hasPermi('distributorIncome:distributorincome:query')")
    @GetMapping(value = "/{distributorId}")
    public AjaxResult getInfo(@PathVariable("distributorId") Long distributorId)
    {
        return success(distributorincomeService.selectDistributorincomeByDistributorId(distributorId));
    }

    /**
     * 新增分销员收入
     */
    @PreAuthorize("@ss.hasPermi('distributorIncome:distributorincome:add')")
    @Log(title = "分销员收入", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Distributorincome distributorincome)
    {
        return toAjax(distributorincomeService.insertDistributorincome(distributorincome));
    }

    /**
     * 修改分销员收入
     */
    @PreAuthorize("@ss.hasPermi('distributorIncome:distributorincome:edit')")
    @Log(title = "分销员收入", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Distributorincome distributorincome)
    {
        return toAjax(distributorincomeService.updateDistributorincome(distributorincome));
    }

    /**
     * 删除分销员收入
     */
    @PreAuthorize("@ss.hasPermi('distributorIncome:distributorincome:remove')")
    @Log(title = "分销员收入", businessType = BusinessType.DELETE)
	@DeleteMapping("/{distributorIds}")
    public AjaxResult remove(@PathVariable Long[] distributorIds)
    {
        return toAjax(distributorincomeService.deleteDistributorincomeByDistributorIds(distributorIds));
    }
}
